package com.design.controller.app;


import com.design.model.BaseResult;
import com.design.model.RecordInfoResponse;
import com.design.model.ShippingInputRequest;
import com.design.service.ShippingRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "【APP端-偏载信息】")
@RequestMapping("/shipping")
@CrossOrigin(origins = "*")
public class ShippingController {
    @Autowired
    private ShippingRecordService service;


    @ApiOperation(value = "偏载信息-信息录入")
    @PostMapping("/inputRecord")
    public BaseResult<Void> updatePassword(@RequestBody ShippingInputRequest request) {
        service.inputRecord(request);
        return new BaseResult<>();
    }

    @ApiOperation(value = "偏载信息-选择车板（列表数据）")
    @GetMapping("/queryCurrentRecord")
    public BaseResult<List<String>> queryCurrentRecord(Long userId) {
        return new BaseResult<>(service.queryCurrentRecord(userId));
    }

    @ApiOperation(value = "偏载信息-车板详情")
    @GetMapping("/queryDetail")
    public BaseResult<RecordInfoResponse> queryCurrentRecord(@RequestParam("userId") Long userId,
                                                             @RequestParam("templateNum") String templateNum) {
        return new BaseResult<>(service.queryCurrentRecordDetail(userId,templateNum));
    }

    @ApiOperation(value = "偏载信息-删除记录")
    @GetMapping("/remove")
    public BaseResult<Void> deleteRecord(@RequestParam("id") Integer id) {
        service.deleteRecord(id);
        return new BaseResult<>();
    }

    @ApiOperation(value = "偏载信息-运输结束")
    @GetMapping("/finish")
    public BaseResult<Void> finish(@RequestParam("userId") Long userId) {
        service.finish(userId);
        return new BaseResult<>();
    }


    @ApiOperation(value = "偏载信息-触发传感器（触发让传感器推送一次数据）")
    @GetMapping("/trigger")
    public BaseResult<Void> trigger() {
        service.trigger();
        return new BaseResult<>();
    }

}
